package chapter4;

import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

public class ButtonEvent3 extends ApplicationWindow{

	public ButtonEvent3() {
		super(null);
	}
	
	@Override
	protected Control createContents(Composite parent) {
		Button button = new Button(parent, SWT.PUSH | SWT.CENTER);
		
		Listener listener = new Listener()
		{

			@Override
			public void handleEvent(Event event) {
				switch (event.type) {
				case SWT.KeyDown:
					if (event.character == 'b') {
						System.out.println("key "+ event.character);
					}
					break;
				case SWT.MouseDown:
					if (event.button == 3) {
						System.out.println("right click");
					}
					break;
				case SWT.MouseDoubleClick:
					System.out.println("double click");
					break;
				}
			}
			
		};
		
		
		button.setText("luik");
		
		button.addListener(SWT.KeyDown, listener);
		button.addListener(SWT.MouseDown, listener);
		button.addListener(SWT.MouseDoubleClick, listener);
			
		return super.createContents(parent);
	}

	public static void main(String[] args) {
		ButtonEvent3 be1 = new ButtonEvent3();
		be1.setBlockOnOpen(true);
		be1.open();
		
		Display.getCurrent().dispose();
	}
}
